package com.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.Goods;
import com.bean.PageBean;
import com.serve.GoodsService;
import com.serveImple.GoodsServiceImpl;

/**
 * Servlet implementation class ShowServlet
 */
@WebServlet("/ShowServlet")
public class ShowServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int defaultPage=1;
		
		//处理从页面分页请求的当前页
		
		PageBean pb=new PageBean();
		pb.setCurrentPage(defaultPage); //默认获取第一页的数据
		
		String str =request.getParameter("currentPage");
		if(str!=null){
			int number=Integer.parseInt(str);
			pb.setCurrentPage(number);
		}
		GoodsService empService=new GoodsServiceImpl();
		List<Goods> goodslist=empService.show(pb);
		System.out.println(goodslist);
		request.setAttribute("pb",pb);
		request.setAttribute("goodslist",goodslist);
		System.out.println("你很烦");
		//转发
		request.getRequestDispatcher("easybuy/goods.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
